//checkboxlist
jQuery.fn.mycomponent = function(obj) {
	try
	{
		var thisCb = $(this);
		var fetchType = obj.fetchType == null ? 'local' : obj.fetchType;
		var direction = obj.direction == null ? 'horizontal' : obj.direction; //vertical
		var comname = obj.name == null ? thisCb.attr('id') : obj.name;
		var key = obj.listKey == null ? 'key' : obj.listKey;
		var value = obj.listValue == null ? 'value' : obj.listValue;
		var type = obj.type;
		var width = obj.width;
		if(width != null && width.indexOf('%') == -1 && width.indexOf('px') == -1)
		{
			width += 'px';
		}
		var headerKey = obj.headerKey;
		var headerValue = obj.headerValue;
		if(type != 'checkbox' && type != 'radio' && type != 'select')
		{
			showMsg(comname + ' type只能为checkbox、radio或select');
			return;
		}
		if('local' == obj.fetchType)
		{
			var opts = eval(obj.data);
			var len = opts.length;
			var com = '';
			var selectOption = '';
			var checkradioOption = '';
			if('select' == type)
			{
				com = '<select style="width:' + width + '" id="' + comname + '" name="' + comname + '">@options</select>';
			}
			for(var i = 0; i < len; i++)
			{
				var optx = opts[i];
				var optxHtml = '';
				if('select' == type)
				{
					optxHtml = '<option value="' + optx[key] + '">' + optx[value] + '</option>';
					selectOption += optxHtml;
				}
				else if('checkbox' == type || 'radio' == type)
				{
					optxHtml = '<input id="' + comname + '-' + (i + 1) + '" name="' + comname + '" type="' + type + '" value="' + optx[key] + '" />' + optx[value] + '&nbsp;';
					if('vertical' == direction)
					{
						optxHtml += '<br/>';
					}
					checkradioOption += optxHtml;
				}
			}
			if('select' == type)
			{
				if(headerKey != null || headerValue != null)
				{
					selectOption = '<option value="' + headerKey + '">' + headerValue + '</option>' + selectOption;
				}
				com = com.replace('@options', selectOption);
			}
			else if('checkbox' == type || 'radio' == type)
			{
				if(headerKey != null || headerValue != null)
				{
					var header = '<input id="' + comname + '-0" name="' + comname + '" type="' + type + '" value="' + headerKey + '" />' + headerValue + '&nbsp;';
					if('vertical' == direction)
					{
						header += '<br/>';
					}
					checkradioOption = header + checkradioOption;
				}
				com = checkradioOption;
			}
			thisCb.html(com);
		}
		else if('remote' == obj.fetchType)
		{
			var url = obj.url;
			if(!isNotNull(url))
			{
				showMsg(comname + ' url不能为空');
				return;
			}
			var params = obj.params;
			var pArr = [];
			var n = 0;
			for(pKey in params)
			{
				var pValue = params[pKey];
				pArr[n] = {'key':pKey, 'value':pValue};
				n++;
			}
			var arrLen = pArr.length;
			for(var i = 0; i < arrLen; i++)
			{
				params['paramObj.' + pArr[i]['key']] = pArr[i]['value'];
			}
			notAsyncAjax(url, params, function(result){
				var opts = result[obj.data];
				if(typeof(result[obj.data]) == 'string')
				{
					opts = eval(result[obj.data]);
				}
				var len = opts.length;
				var com = '';
				var selectOption = '';
				var checkradioOption = '';
				if('select' == type)
				{
					com = '<select style="width:' + width + '" id="' + comname + '" name="' + comname + '">@options</select>';
				}
				for(var i = 0; i < len; i++)
				{
					var optx = opts[i];
					var optxHtml = '';
					if('select' == type)
					{
						optxHtml = '<option value="' + optx[key] + '">' + optx[value] + '</option>';
						selectOption += optxHtml;
					}
					else if('checkbox' == type || 'radio' == type)
					{
						optxHtml = '<input id="' + comname + '-' + (i + 1) + '" name="' + comname + '" type="' + type + '" value="' + optx[key] + '" />' + optx[value] + '&nbsp;';
						if('vertical' == direction)
						{
							optxHtml += '<br/>';
						}
						checkradioOption += optxHtml;
					}
				}
				if('select' == type)
				{
					if(headerKey != null || headerValue != null)
					{
						selectOption = '<option value="' + headerKey + '">' + headerValue + '</option>' + selectOption;
					}
					com = com.replace('@options', selectOption);
				}
				else if('checkbox' == type || 'radio' == type)
				{
					if(headerKey != null || headerValue != null)
					{
						var header = '<input id="' + comname + '-0" name="' + comname + '" type="' + type + '" value="' + headerKey + '" />' + headerValue + '&nbsp;';
						if('vertical' == direction)
						{
							header += '<br/>';
						}
						checkradioOption = header + checkradioOption;
					}
					com = checkradioOption;
				}
				thisCb.html(com);
			});
		}
	}
	catch (e) {
		alert(e.message);
	}
	finally
	{
	}
};

function notAsyncAjax(url, params, func)
{
	$.ajax({
		url:realPath + '/' + url,
		type:'get',
		data:params,
		dataType:'json',
		async: false,
		success:function(result){
			func(result);
		},
		error:function(XmlHttpRequest,textStatus, errorThrown)
		{
			showMsg('操作失败：' + XmlHttpRequest.responseText);
		}
	});
}